package com.demo2do.fms.scheduler.entity;

import java.util.Date;

import org.apache.commons.lang3.StringUtils;

import com.demo2do.fms.entity.vehicle.source.LockType;


/**
 *
 * @author Ark
 *
 */
public class VehicleSource {

	/** id */
	private Long id;
	
	/** 车辆代码 */
	private String code;
	
	/** 锁定状态 */
	private int locking;
	
	/** 审核状态 */
	private String status;
	
	/** 同步状态 */
	private int synchronize;
	
	/** 锁定类型 */
    private String lockType;
    
    /** 锁定备注 */
    private String lockReason;
    
    /** 最近修改时间 */
    private Date lastModifyTime;

	/**
	 * The default constructor
	 */
	public VehicleSource() {
	}

	/**
	* @description
	* @params [id, code, locking, status, synchronize, lockType, lockReason, lastModifyTime]
	* @return
	* @author LZJ
	* @date 2020/12/2 16:30
	**/
	public VehicleSource(Long id, String code, int locking, String status, int synchronize, String lockType, String lockReason, Date lastModifyTime) {
		this.id = id;
		this.code = code;
		this.locking = locking;
		this.status = status;
		this.synchronize = synchronize;
		this.lockType = lockType;
		this.lockReason = lockReason;
		this.lastModifyTime = lastModifyTime;
	}

	/**
     * @return
     */
    public boolean isUnsynchro() {
        return (!StringUtils.equals("SYNCED", status)) && synchronize == 0;
    }
    
    /**
     * 
     * @return
     */
    public boolean isLock() {
        return locking == 1;
    }
    
    /**
     * 
     * @param reason
     * @param lockType
     * @return
     */
    public VehicleSource doLock(String reason, LockType lockType) {
    	
        this.locking = 1;
        this.lockReason = reason;
        
        if (lockType != null) {
        	this.lockType = lockType.name();
        }
        
        this.lastModifyTime = new Date();
        return this;
        
    }
    
    /**
     * @return
     */
    public VehicleSource unlock() {
        this.locking = 0;
        this.lockReason = null;
        this.lockType = null;
        this.lastModifyTime = new Date();
        return this;
    }

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @return the code
	 */
	public String getCode() {
		return code;
	}

	/**
	 * @return
	 */
	public int getLocking() {
		return locking;
	}

	/**
	 * @return the status
	 */
	public String getStatus() {
		return status;
	}

	/**
	 * @return
	 */
	public int getSynchronize() {
		return synchronize;
	}

	/**
	 * @return the lockType
	 */
	public String getLockType() {
		return lockType;
	}

	/**
	 * @return the lockReason
	 */
	public String getLockReason() {
		return lockReason;
	}

	/**
	 * @return the lastModifyTime
	 */
	public Date getLastModifyTime() {
		return lastModifyTime;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @param code the code to set
	 */
	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * @param locking
	 */
	public void setLocking(int locking) {
		this.locking = locking;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(String status) {
		this.status = status;
	}

	/**
	 * @param synchronize
	 */
	public void setSynchronize(int synchronize) {
		this.synchronize = synchronize;
	}

	/**
	 * @param lockType the lockType to sejit
	 */
	public void setLockType(String lockType) {
		this.lockType = lockType;
	}

	/**
	 * @param lockReason the lockReason to set
	 */
	public void setLockReason(String lockReason) {
		this.lockReason = lockReason;
	}

	/**
	 * @param lastModifyTime the lastModifyTime to set
	 */
	public void setLastModifyTime(Date lastModifyTime) {
		this.lastModifyTime = lastModifyTime;
	}
	
}
